<?php


namespace api\web\controller;

use api\web\model\GoodsModel;
use cmf\controller\RestBaseController;

class GoodsController extends RestBaseController
{
    public function index()
    {
        $list = GoodsModel::select();
        $this->success('商品显示',$list);
    }

    //查看商品详情
    public function getGoodsInfo(){
        $goods_id = input('goods_id/d');
        $goods = GoodsModel::where('id',$goods_id)->find();
        unset($goods['info']);
        $goodsAttr = json_decode($goods['attr'],true);
        foreach ($goodsAttr as $key => $val){
            $goodsAttr[$key]['attr_value'] = explode(',',$val['attr_value']);
        }
        $goods['attr'] = $goodsAttr;
        $this->success('商品详情',$goods);
    }

}